package com.happy.cat.project.system.controller;

import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.project.system.domain.CatOrderSetting;
import com.happy.cat.project.system.service.ICatOrderSettingService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统订单设置Controller
 *
 * @author verne
 * @date 2020-08-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/catOrderSetting" )
@Api("系统订单设置 API")
public class CatOrderSettingController extends BaseController {

    private final ICatOrderSettingService iCatOrderSettingService;

    /**
     * 获取系统订单设置详细信息
     */
    @ApiOperation(value = "获取系统订单设置详细信息",notes = "获取系统订单设置详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catOrderSetting:query')" )
    @GetMapping(value = "/info" )
    public AjaxResult getInfo() {
        List<CatOrderSetting> list = iCatOrderSettingService.list();
        if(list.size()>0){
            return AjaxResult.success(list.get(0));
        }
        return AjaxResult.success(null);
    }

    /**
     * 修改系统订单设置
     */
    @ApiOperation(value = "修改系统订单设置",notes = "修改系统订单设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catOrderSetting:edit')" )
    @Log(title = "系统订单设置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatOrderSetting catOrderSetting) {
        return toAjax(iCatOrderSettingService.saveOrUpdate(catOrderSetting) ? 1 : 0);
    }

}
